//
//  MessageViewController.m
//  AoJi
//
//  Created by IMacLife on 15/2/4.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//

#import "MessageViewController.h"

@implementation MessageViewController
{
    UIActivityIndicatorView *_activity;  //菊花
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}


-(void)loadView
{
    [super loadView];
    
    //自定义titleview
    UIView *titleview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    [titleview setBackgroundColor:[UIColor colorWithRed:249.0f/255.0f green:249.0f/255.0f blue:249.0f/255.0f alpha:1.0f]];
 
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame=CGRectMake(0, 20, 44, 44);
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backButton) forControlEvents:UIControlEventTouchUpInside];
    [titleview addSubview:backBtn];
    [self.view addSubview:titleview];

    
    //id等于cell的id(object_id)
    UIWebView *message = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)];
    
    //activity  lecture  route
    if ([self.objType isEqualToString:@"route"]) {
        NSString *urlStr =[@"http://cent.dsgrd.com/tour/recomcircuit/detail?id=" stringByAppendingString:self.objid];
        [message loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
        [self.view addSubview:message];
    }else{
    NSString *url = [NSString stringWithFormat:@"http://cent.dsgrd.com/study/%@/detail?id=",self.objType];
    NSString *urlStr = [url stringByAppendingString:self.objid];
    [message loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
    [self.view addSubview:message];
    }
}

-(void)backButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

//开始加载
-(void)webViewDidStartLoad:(UIWebView *)webView
{
    //系统灰色的菊花
    _activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activity.center = self.view.center;
    [self.view addSubview:_activity];
    [_activity startAnimating]; //开始动画
}

//加载完成
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_activity stopAnimating];
    [_activity removeFromSuperview];
    _activity = nil;
}

//加载失败
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [_activity stopAnimating];
    [_activity removeFromSuperview];
    _activity = nil;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
